
 //验证
 var wrongTypeName=0;
 var wrongTypePwd=0;
 var autologin=false;
 var wrongTypePwd;
 var wrongPhoneHtml = new Array("","请输入手机号","手机号的长度必须是11位","请输入正确的手机号","您的用户名或密码错误","超时,请重新登陆");
 var wrongPwdHtml = new Array("","请输入密码","密码长度小于6位","","密码中含有非法字符");
 var pwdFlag = false;


  //失去焦点后验证格式是否正确
 function validate(obj){
	 var objid = $(obj).attr("id");
	 if(objid=="phoneNum"){
		 wrongTypePhone = 0;
		 var phoneNum = $("#phoneNum").val();
		 phoneLength=phoneNum.length;
		 if(phoneLength==0)
			wrongTypePhone =1;
		 else if(phoneLength!=11){
			wrongTypePhone =2;
		 }else{
			 var phoneParth =  /^1[3,5,8]\d{9}$/;;
			 if(!phoneParth.exec(phoneNum)){
				 wrongTypePhone = 2;
			 }else{
				wrongTypePhone=0;
			 }
		}
		$("#msg1").html(wrongPhoneHtml[wrongTypePhone]);
		if(wrongTypePhone==0){
			return true;
		}else{
			return false;
		}
	 }else{
		 wrongTypePwd = 0;
		 var password = $("#password").val();
		 pwdLength=password.length;
		
		if(password==0)
		   wrongTypePwd = 1;
		 else{
			 var pwdParth = /^(\w){6,20}$/; 
			 if(pwdLength<6)
				wrongTypePwd=2;
			 if(pwdLength>50)
				wrongTypePwd=3;
			 if(pwdLength>6&&pwdLength<20){
			   if(!pwdParth.exec(password))
			   wrongTypePwd=4;
			 }
			 }
		   $("#msg2").html(wrongPwdHtml[wrongTypePwd]);
		   if(wrongTypePwd==0){
			  return true;
			}else{
				return false;
			}
	  }
	   
	   if( wrongTypePwd== 0 && wrongTypePhone== 0 ){
		  
		 }
	 }
	 
	 	 
//页面加载
	$(document).ready(function(e){
		versionFlag=="jx"?$(".img_center").attr("class","img_center1"):null;
		if($.cookie("user")=='1'){
		if($.cookie("phoneNum")!=null&&$.cookie("password")!=null){
		//给文本框赋值
	    $("#phoneNum").attr("value",$.cookie('phoneNum'));
	    $("#password").attr("value",$.cookie('password'));
		//If记住密码勾选了
		if($.cookie("is_jizhumima")=='1'){
			//给自动登陆和设置为选中状
		   $("#check_jzmm").attr("checked","checked");
		   $("#div_jzmm").attr("class","check");      
		}
		if($.cookie("is_autologin")=='1'){
			autologin=true;
		   //给自动登陆和保存密码设置为选中状态
	       $("#check_jzmm").attr("checked","checked");
		   $("#check_zddl").attr("checked","checked");
		   $("#div_jzmm").attr("class","check");
		   $("#div_zddl").attr("class","check");
		   //点注销时，传值过来，让autologin==false
		   if($.getUrlParam("autologin")=="false"){
			 autologin=false;
		   }
		   auto_login_bys3();
		}		
		}else{
			
		}
		}
	});
	
function wait_me(){
	autologin = false;
}	
	 
//页面加载
/*	$(document).ready(function(e){
		if($.cookie("phoneNum")!=null&&$.cookie("password")!=null){
		//给文本框赋值
	    $("#phoneNum").attr("value",$.cookie('phoneNum'));
	    $("#password").attr("value",$.cookie('password'));
		//If记住密码勾选了
		if($.cookie("is_jizhumima")=='1'){
			//给自动登陆和设置为选中状
		   $("#check_jzmm").attr("checked","checked");
		   $("#div_jzmm").attr("class","check");      
		}
		if($.cookie("is_autologin")=='1'){
			autologin=true;
		   //给自动登陆和保存密码设置为选中状态
	       $("#check_jzmm").attr("checked","checked");
		   $("#check_zddl").attr("checked","checked");
		   $("#div_jzmm").attr("class","check");
		   $("#div_zddl").attr("class","check");
		   //点注销时，传值过来，让autologin==false
		   alert($.getUrlParam("autologin"));
		   if($.getUrlParam("autologin")=="false"){
			 autologin=false;
		   }
		   auto_login_bys3();
		}		
		}else{
			
		}
	});
	
	*/
//忘记密码
function forget_mima(){
   autologin=false;
  if($("#phoneNum").val()==null&&$("#phoneNum").val()==""){
	   jAlert("请输入手机号!",'系统提示');
  }
  else{
	$.natureajax({
	  url:jsonserver+"/login_forgetPassword.do?callback=?",
	  data:{"NP_INFO_TELNO":$("#phoneNum").val()},
	  type:"POST",
	  dataType:"jsonp",
	  success:function(data){
		  if(data[0].result=='1'){
			 jAlert("已发送到"+data[1].email+"邮箱",'系统提示');
		  }
		  if(data[0].result=='240'){
			jAlert(data[0].info,'系统提示');
		  }if(data[0].result=='248'){
			 jAlert(data[0].info,'系统提示');
		  }if(data[0].result=='210'){
			 jAlert(data[0].info,'系统提示');
		  }
	  },error:function(){
		 jAlert("请求出错,请重新输入！",'系统提示');
	  }  
  });  
  }
	  	
}
    
	 //登陆
	 function function_load(){
		if(validate($("#phoneNum")) && validate($("#password"))){
			  $.natureajax({
			  url:jsonserver+"/login_getUseValidate.do?callback=?",
			  type:"GET",
			  data:{"phonenum":$("#phoneNum").val(),"passwd":base64encode($("#password").val())},
			  dataType:"jsonp", 
			  success: function(data){
				   if(data[0].result=="1"){
					 $.cookie("user",'1',{path:"/",expires:15});
					 $.cookie("NP_INFO_ID",data[2].NP_INFO_ID,{path:"/"});
			         $.cookie("NP_INFO_TELNO",data[2].NP_INFO_TELNO,{path:"/"});
					 if(data[1]==""||data[1]==null){
						$.cookie("newuser","isNull",{path:"/"});
					 }else{
						 $.cookie("newuser","isFull",{path:"/"});
					 }
			         $.cookie("U_KEY",data[2].ukey,{path:"/"});
			         $.cookie("IS_BJ_LT",data[2].IS_BJ_LT,{path:"/"});
					 $.cookie("LT_VIP",data[2].LT_VIP,{path:"/"});
					 $.cookie("phoneNum",data[2].NP_INFO_TELNO,{path:"/",expires:15});
					 $.cookie("email",data[2].NP_EMAIL,{path:"/",expires:15});
					 $.cookie("password1",base64encode($("#password").val()),{path:"/",expires:15});
					 autologincheck();
					 window.location.href="index.html";
					 }else{
						 jAlert("用户名或者密码错误！请重新输入。",'系统提示');
					 }
			
			 },error: function(){
				   jAlert("请求失败，请稍后再试。。",'系统提示');
				}
			 }); 
		 }else{ 
			jAlert("用户名或者密码为空或者输入有误，请重新输入!",'系统提示');

		  }
		  
		 }
		 
//记住密码是否选中
function writemimacookie(){
	if($("#check_jzmm").attr("checked")=="checked"){
			//保存   保存密    码选中
			 $.cookie("is_jizhumima","1",{path:"/",expires:15});
			 $.cookie("phoneNum",$("#phoneNum").val(),{path:"/",expires:15});
			 $.cookie("password",$("#password").val(),{path:"/",expires:15});
	}else{
		$.cookie("is_jizhumima","0",{path:"/",expires:15});
	 }
}

//自动登陆是否选中
function autologincheck(){
	if($("#check_zddl").attr("checked")=="checked"){
		//保存自动登陆选中状态
		$.cookie("is_autologin","1",{path:"/",expires:15});
		//保存记住密码选中状态
		$.cookie("is_jizhumima","1",{path:"/",expires:15});
		
		$("#check_jzmm").attr("class","check");
		$("#check_zddl").attr("class","check");
	}else{
		$.cookie("is_autologin","0",{path:"/",expires:15});
	}
	writemimacookie();
}



//等待3秒自动登陆
var t = 4;
function auto_login_bys3(){
t--;
if (t==0){
	if(autologin){
		function_load();
	}
}else{
 
}
	setTimeout("auto_login_bys3()",1000);
}


//跳转到新用户登陆页面
function newuser_htm(){
	window.location.href="newuser_login.html";
}

//改变状态
  function chageStatus(a){
	    if($("#check_"+a).attr("checked")=="checked"){
			$("#div_"+a).attr("class","uncheck");
			$("#check_"+a).removeAttr("checked");
		}else{
			$("#div_"+a).attr("class","check");
			$("#check_"+a).attr("checked","checked");
		}
		autologin=false;
	}



/**	-------------------------------------------滑动时头部固定不动------------------ --------------------------------------*/



